<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>选项卡</title>
    <style>
        ul,
        li {
            list-style: none;
        }


        .box {
            width: 300px;
            height: 200px;
            color: black;
            font-size: larger;
            text-align: center;
            line-height: 200px;
            background-color: darkkhaki;
            display: none;
        }

        .active {
            display: block;
        }
    </style>
</head>

<body>
    <div id="app">
        <ul>
            <li v-for="(item,index) in title" @click="changeIndex(index)"><button>{{ item.item }}</button></li>
        </ul>

        <ul>
            <li v-for="(item,index) in contents">
                <!-- <div :class="{box:isActive}" v-if="index==flag">{{ item.item }}</div> -->
                <div :class="{box:isActive,active:(index == flag)}">{{ item.item }}</div>
            </li>
        </ul>
    </div>

    <script src="../vue.js"></script>

    <script>
        new Vue({
            el: "#app",
            data: {
                title: [
                    { item: 'html' },
                    { item: 'css' },
                    { item: 'js' },
                    { item: 'vuejs' }],
                contents: [
                    { item: 'html-contents' },
                    { item: 'css-contents' },
                    { item: 'js-contents' },
                    { item: 'vuejs-contents' }],
                isActive: true,
                flag: 0
            },
            methods: {
                changeIndex(boxIndex) {
                    this.flag = boxIndex;
                },
            }
        })
    </script>
</body>

</html>